/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package esnipe2;

import java.util.ArrayList;

/**
 *
 * @author hangsu
 */
public class StubAPIImpl implements EbayAPI {

    private boolean isConnected;
    private ArrayList<String> placed;

    public StubAPIImpl(){
        this.isConnected = false;
        this.placed = new ArrayList<String>();
    }

    @Override
    public boolean startSession(String userid, String pass) {
        this.isConnected = true;
        return true;
    }

    @Override
    public boolean closeSession() {
        this.isConnected = false;
        return true;
    }

    @Override
    public boolean getItemInfo(EbayItem item) {
        if(!isConnected) return false;
        item.currentPrice = new Pricepair(10, true);
        item.itemName = "Test Item";
        //Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("PST"));
        //cal.add(Calendar.MINUTE, 3);
        //item.endTime = cal;
        return true;
    }

    @Override
    public Pricepair getCurrentPrice(String url) {
        if(!isConnected) return new Pricepair(10, false);
        return new Pricepair(10, true);
    }

    @Override
    public ItemResult getResult(String url) {
        if(!isConnected) return ItemResult.RESULT_UNKNOWN;
        if(!this.placed.contains(url)) return ItemResult.RESULT_UNKNOWN;
        return ItemResult.RESULT_UNKNOWN;
    }

    @Override
    public boolean placeBid(String url, double val) {
        //throw new UnsupportedOperationException("Not supported yet.");
        if(!isConnected) return false;
        if(this.placed.contains(url)) return false;
        this.placed.add(url);
        return true;
    }
}
